• File: hub_import_done_maintain_get_1.php
  • Full Path: ../saved/hub_import_done_maintain_get_1.php
  • Date Modified: 30.04.25 07:56:06
  • File size: 6.23 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php
//======================================================================================
//
// Function: Get hub_config => DATA-HUB - IFS log
//
// Programmer: JKJ
// Date      : 2024-07-05
//
// Copyright Reeft A/S (c) - 2024
//======================================================================================

//======================================================================================
// General config
//======================================================================================
	include "config/config.php";

//======================================================================================
// Get input
//======================================================================================

	if (isset($_REQUEST["hub_webnam"])) {
		$hub_webnam = strtoupper($_REQUEST["hub_webnam"]);
	} else {
		$hub_webnam = '';
	}

	if (isset($_REQUEST["hub_ifsfil"])) {
		$hub_ifsfil = $_REQUEST["hub_ifsfil"];
	} else {
		$hub_ifsfil = '';
	}

	if (isset($_REQUEST["hub_packno"])) {
		$hub_packno = $_REQUEST["hub_packno"];
	} else {
		$hub_packno = '';
	}

	if (isset($_REQUEST["hub_timstp"])) {
		$hub_timstp = $_REQUEST["hub_timstp"];
	} else {
		$hub_timstp = '';
	}
	
	if (isset($_REQUEST["fromdate"])) {
		$fromdate = $_REQUEST["fromdate"];
	} else {
		$fromdate = '';
	}
	
	if (isset($_REQUEST["todate"])) {
		$todate = $_REQUEST["todate"];
	} else {
		$todate = '';
	}

	if (isset($_REQUEST["myPageGoTo"])) {
		$myPageGoTo = $_REQUEST["myPageGoTo"];
	} else {
		$myPageGoTo = 0;
	}

	if (isset($_REQUEST["myOffSet"])) {
		$myOffSet = $_REQUEST["myOffSet"];
	} else {
		$myOffSet = 0;
	}

	if (isset($_REQUEST["myPageSize"])) {
		$myPageSize = $_REQUEST["myPageSize"];
	} else {
		$myPageSize = 0;
	}

	if (isset($_REQUEST["search_arg"])) {
		$search_arg = $_REQUEST["search_arg"];
	} else {
		$search_arg = '';
	}

	//$search_arg = urldecode($search_arg);

	$search_arg = str_replace(' ', "|", $search_arg);

//======================================================================================
// Get input
//======================================================================================

// Subtract one month from the current date
if ( $fromdate == '' ) {
	$date = new DateTime();
	$date->modify('-1 month');
	$fromdate = $date->format('Y-m-d');
}

if ( $todate == '' ) {
	$date = new DateTime();
	$todate = $date->format('Y-m-d');
}

//======================================================================================
// Get session variables
//======================================================================================
	include "include/getsession.php";

//======================================================================================
// Set language
//======================================================================================
	include "include/set_language.php";

//======================================================================================
// Connect to SQLite database in file
//======================================================================================

	$entries_found					= 0;

	$returnCode 					= '99';
	$returnMsg 						= 'No data found';

	$currentDate = date('Y-m-d');
	$currentTime = date('H:i:s');

//======================================================================================
// Set header
//======================================================================================

	header('Content-Type: application/json;charset=utf-8');

//======================================================================================
// Get time stamp
//======================================================================================
	$timeStamp = '';
	if ( $timeStamp == '' ) {
		$now = DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''));
		$timeStamp = $now->format("Y-m-d H:i:s");
	}


	$data = array(
		"timestamp" => $timeStamp,
		"hub_webnam" => $hub_webnam,
		"hub_ifsfil" => $hub_ifsfil,
		"hub_ifsfil" => $hub_packno,
		"hub_ifsfil" => $hub_timstp,
		"fromdate" 	 => $fromdate,
		"todate" 	 => $todate,
		"myPageGoTo" => $myPageGoTo,
		"myOffSet"   => $myOffSet,
		"myPageSize" => $myPageSize
		);

	// print_r($data);

	// echo $search_arg;
	// exit;


//======================================================================================
// Make call to API somewhere
//======================================================================================

	$jsonData = json_encode($data);
	//header('Content-Type: application/json');

	$json_pretty = json_encode(json_decode($jsonData), JSON_PRETTY_PRINT);
	// echo $json_pretty;
	// echo "<br>";
	// echo $url;

	$headers = array(
         "Content-type: Content-Type:application/json",
		 "User-Agent: DATA-HUB 1.0",
         "APIKEY: $DFT_API_KEY"
     );

	$parms 	= '?'
			. 'hub_webnam=' . trim( $hub_webnam )
			. '&hub_ifsfil=' . trim( $hub_ifsfil )
			. '&hub_packno=' . trim( $hub_packno )
			. '&hub_timstp=' . trim( $hub_timstp )
			. '&fromdate=' . trim( $fromdate )
			. '&todate=' . trim( $todate )
			. '&myPageGoTo=' . $myPageGoTo
			. '&myOffSet=' . $myOffSet
			. '&myPageSize=' . $myPageSize
			. '&mySearchArg=' . $search_arg
			;


	// Set URL
	$url = $DFT_WEBSERVICE_URL_DATAHUB . '/' . 'HUB_IMPLOG';

	// Add parms
	$url = $url . $parms;

	//echo $url;

	// Create a new cURL resource
	$ch = curl_init($url);


	// Attach encoded JSON string to the POST fields
	curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

	// Set the content type to application/json
	//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );

	// Return response instead of outputting
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_POST, false);
	//curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' );
	curl_setopt($ch, CURLOPT_HEADER, false);    // we do not need headers
	curl_setopt($ch, CURLOPT_NOBODY, false);    // we don't need body

	// Execute the GET request
	$result = curl_exec($ch);

	$ary	= curl_getinfo($ch);

	// Close cURL resource
	curl_close($ch);

	//print_r($ary);
	print_r($result);

?>